// pages/event/reporting/reporting.js
import Dialog from "../../../miniprogram_npm/@vant/weapp/dialog/dialog"
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
const app = getApp()
const log = new app.appLogs()
const http = new app.appHttp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        Reportinglist: [],
        isLoading: true,
        PageNumber: 1,

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            Reportinglist:[]
        })
        this.getReportinglist()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.setData({
            PageNumber: 1,
            Reportinglist: []
        })
        this.getReportinglist()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.data.PageNumber += this.data.PageNumber
        this.getReportinglist()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    /**
     * 请求列表
     */
    getReportinglist() {
        const than = this
        this.setData({
            isLoading: true
        })
        http.get("event/info/page/id", {
            page_number: than.data.PageNumber,
            page_size: 10,
            source: 2,
        }).then((res) => {
            res.data.data.list.forEach(item => {
                than.data.Reportinglist.push(item)
            })
            than.setData({
                Reportinglist: than.data.Reportinglist,
                isLoading: false
            })
            wx.stopPullDownRefresh();
            if (res.data.data.list.length == 0) {
                Toast.fail("没有更多的数据了")
            } else {
                Toast.success("数据加载完成")
            }
        })
    },
    /**
     *随手报详情跳转
     * @param event
     */
    onReporting: function (event) {
        const id = event.currentTarget.dataset.id
        wx.navigateTo({
            url: '../reporting/reportingdetails/reportingdetails?id=' + id
        })
    }
})